home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / Watcher / doit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-02  |  1.5 KB  |  69 lines

  1. /*
  2.    doit: here is where the real purpose of the program is actually
  3.    carried out.  
  4.  
  5.     for each command, run it and look for problems.
  6.     write info from this run to the history file.
  7.  
  8.    Kenneth Ingham
  9.  
  10.    Copyright (C) 1987 The University of New Mexico
  11. */
  12.  
  13. #include "defs.h"
  14.  
  15. doit(hf)
  16. FILE *hf;
  17. {
  18.     extern struct cmd_st *clist;
  19.     extern int vflag, nflag;
  20.     extern int cmd_ok;
  21.     extern int errno;
  22.     extern char *sys_errlist[];
  23.  
  24.     char line[MAX_STR];
  25.     struct cmd_st *p;
  26.     struct old_cmd_st *prev_results, *find_cmd_prev();
  27.     FILE *ps, *popen();
  28.  
  29.     /* run commands */
  30.     for (p=clist; p != NULL; p=p->next) {
  31.         cmd_ok = True;
  32.         if (vflag)
  33.             printf("Executing: '%s'\n\n", p->pipeline);
  34.  
  35.         if ( ! nflag ) {
  36.             /* dealing with the history file... */
  37.             if (p->key != NULL && ! nflag)
  38.                 fprintf(hf, "%s\n", p->pipeline);
  39.             /* get prev results for comparison */
  40.             prev_results = find_cmd_prev(p->pipeline);
  41.         }
  42.         else
  43.             prev_results = NULL;
  44.  
  45.         if ((ps = popen(p->pipeline, "r")) == NULL) {
  46.             fprintf(stderr, "Unable to popen '%s': %s\n", 
  47.                 p->pipeline, sys_errlist[errno]);
  48.             fprintf(stderr, "Going to next pipeline.\n");
  49.             continue;
  50.         }
  51.  
  52.         while (fgets(line, MAX_STR, ps) != NULL) {
  53.             line[strlen(line)-1] = '\0'; /* remove newline */
  54.             if (vflag)
  55.                 printf("  Read: '%s'\n",line);
  56.             checkline(p, line, prev_results, hf);
  57.             errno = 0;
  58.         }
  59.  
  60.         if (errno)
  61.             fprintf(stderr, "Error reading from '%s': %s\n",
  62.                 p->pipeline, sys_errlist[errno]);
  63.  
  64.         (void) pclose(ps);
  65.         if (!cmd_ok)
  66.             printf("\n");
  67.     }
  68. }
  69.